package com.spring.showcase.exceptions;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(value = CustomException.class)
    public ModelAndView handleCustomException(Exception exception) {
        ModelAndView model = new ModelAndView();
        model.addObject("error", exception.getMessage());
        model.setViewName("error");
        return model;
    }

}
